package com.webserver.core;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ClientHandler implements Runnable{
    private Socket socket;

    public ClientHandler(Socket socket) {
        this.socket = socket;
    }
    public void run(){
        try {
            InputStream in = socket.getInputStream();
            int b;
            char cur = 'a',pre = 'a';
            StringBuilder stringBuilder = new StringBuilder();
            while ((b = in.read()) != -1){
                cur =(char) b;
                stringBuilder.append(cur);
                if(cur == 10 && pre == 13){
                    break;
                }
                pre = cur;
            }
            String line = stringBuilder.toString().trim();
            System.out.println(line);

            String method,uri,protocol;
            String[] data = line.split("\\s");
            method = data[0];
            uri = data[1];
            protocol = data[2];
            System.out.println("method:"+method);
            System.out.println("uri:"+uri);
            System.out.println("protocol:"+protocol);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

}
